<div class="tabbable tabs-left">
    <?php echo $this->partial('analytics/analytics/left_menu.phtml'); ?>
    <div class="tab-content">
        <style>
            .table td {
                border-top: 0;
            }
        </style>
        <table class="table table-striped table-bordered">
            <thead>
            <th><?php echo $this->translate('分类销售分析'); ?></th>
            </thead>
            <tbody>
            <tr>
                <td colspan="3">
                    <div class="alert alert-info">
                        <strong><?php echo $this->translate('说明：各个分类的总金额之和可能会比实际总金额多一些，因为在订单中有订单优惠存在(如满多少减n元、购物优惠券等)，这些优惠在以各个分类进行统计时，是无法均分到各个商品内，所以分类对应的总金额是未优惠金额。'); ?></strong>
                    </div>
                </td>
            </tr>
            <tr>
                <td width="33%"><b><?php echo $this->translate('当前销售总额'); ?>：</b><?php echo number_format($this->order_total[0]['order_total'], 2, '.', ''); ?></td>
                <td width="33%"><b><?php echo $this->translate('当前未付款总额'); ?>：</b><?php echo number_format($this->order_d_pay_total[0]['order_total'], 2, '.', ''); ?></td>
                <td width="33%"><b><?php echo $this->translate('当前已付款总额'); ?>：</b><?php echo number_format($this->order_pay_total[0]['order_total'], 2, '.', ''); ?></td>
            </tr>
            <tr style="font-weight: bold;">
                <form method="get" name="order_stats_form" id="order_stats_form" action="">
                    <input type="hidden" name="dateNum" value="<?php if($this->date_num > 0) echo $this->date_num+1; ?>">
                    <td colspan="4" style="text-align: right;line-height: 40px;">
                        <a href="<?php echo $this->url('analytics/default', array('controller'=>'Analytics', 'action'=>'classSaleStats'), array('query'=>array('dateNum'=>7))) . ((isset($this->group_id) and $this->group_id > 0) ? '&group_id='.$this->group_id : '') . ((isset($this->class_id) and $this->class_id > 0) ? '&class_id='.$this->class_id : ''); ?>" class="btn <?php if($this->date_num == 6) echo 'btn-primary'; ?>"><?php echo $this->translate('最近7天'); ?></a>&nbsp;
                        <a href="<?php echo $this->url('analytics/default', array('controller'=>'Analytics', 'action'=>'classSaleStats'), array('query'=>array('dateNum'=>30))) . ((isset($this->group_id) and $this->group_id > 0) ? '&group_id='.$this->group_id : '') . ((isset($this->class_id) and $this->class_id > 0) ? '&class_id='.$this->class_id : ''); ?>" class="btn <?php if($this->date_num == 29) echo 'btn-primary'; ?>"><?php echo $this->translate('最近30天'); ?></a>&nbsp;&nbsp;
                        <select name="class_id" onchange="submit_form()" class="span2" style="width: 150px;">
                            <option value=""><?php echo $this->translate('选择商品分类'); ?></option>
                            <?php
                            if ($this->class_array) {
                            foreach ($this->class_array as $class_val) {
                            ?>
                            <option value="<?php echo $class_val['class_id']; ?>" <?php if(isset($this->class_id) and $this->class_id == $class_val['class_id']) echo 'selected'; ?>>
                                <?php echo str_repeat('&nbsp;', $class_val['class_level'] * 5); ?>
                                <?php echo $this->escapeHtml($class_val['class_name']); ?>
                            </option>
                            <?php
                            } }
                            ?>
                        </select>
                        &nbsp;&nbsp;
                        <select name="group_id" onchange="submit_form()" class="span2" style="width: 150px;">
                            <option value=""><?php echo $this->translate('选择客户组'); ?></option>
                            <?php if(!empty($this->group_array)) { foreach($this->group_array as $group_value) { ?>
                                <option value="<?php echo $group_value['group_id']; ?>" <?php if(isset($this->group_id) and $this->group_id == $group_value['group_id']) echo 'selected'; ?>><?php echo $this->escapeHtml($group_value['group_name']); ?></option>
                            <?php } } ?>
                        </select>
                        <input type="text" class="span2 Wdate" name="start_time" id="start_time" value="<?php if(isset($this->start_time)) echo $this->start_time; ?>" onclick="WdatePicker({el:'start_time', dateFmt:'yyyy-MM-dd'})">
                        ~
                        <input type="text" class="span2 Wdate" name="end_time" id="end_time" value="<?php if(isset($this->end_time)) echo $this->end_time; ?>"  onclick="WdatePicker({el:'end_time', dateFmt:'yyyy-MM-dd'})">
                        <button type="submit" class="btn btn-primary"><?php echo $this->translate('查看'); ?></button>
                    </td>
                </form>
            </tr>
            <tr>
                <td colspan="4">
                    <div id="user_chart" style="width: 100%;height: 400px;margin-top: 20px;"></div>
                </td>
            </tr>
            <tr>
                <td colspan="3">
                    <table class="table table-striped table-bordered">
                        <tr>
                            <td width="50%">
                                <div id="goods_class_chart" style="width: 100%;height: 400px;margin-top: 50px;"></div>
                            </td>
                            <td width="50%">
                                <div id="user_group_chart" style="width: 100%;height: 400px;margin-top: 50px;"></div>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="4">
                    <table class="table table-hover table-striped table-bordered">
                        <tr>
                            <td width="10%" style="background:#CCC;"><b><?php echo $this->translate('排行'); ?></b></td>
                            <td width="30%" style="background:#CCC;"><b><?php echo $this->translate('商品名称'); ?></b></td>
                            <td width="15%" style="background:#CCC;"><b><?php echo $this->translate('商品货号'); ?></b></td>
                            <td width="15%" style="background:#CCC;"><b><?php echo $this->translate('商品销量'); ?></b></td>
                            <td width="15%" style="background:#CCC;"><b><?php echo $this->translate('商品销售额'); ?></b></td>
                            <td width="15%" style="background:#CCC;"><b><?php echo $this->translate('商品均价'); ?></b></td>
                        </tr>
                        <?php
                        if($this->order_goods_list) {
                            foreach ($this->order_goods_list as $g_key => $g_value) {
                                ?>
                                <tr>
                                    <td><?php echo $this->page_base_num + $g_key+1; ?></td>
                                    <td><?php echo $this->escapeHtml($g_value['goods_name']); ?></td>
                                    <td><?php echo $g_value['goods_item']; ?></td>
                                    <td><?php echo $g_value['buy_g_num']; ?></td>
                                    <td><?php echo number_format($g_value['goods_g_amount'], 2, '.', ''); ?></td>
                                    <td><?php echo number_format($g_value['goods_g_amount']/$g_value['buy_g_num'], 2, '.', ''); ?></td>
                                </tr>
                            <?php } } ?>
                        <tr>
                            <td colspan="6" style="background:#FFF">
                                <?php echo ( count($this->order_goods_list) > 0 ) ? $this->paginationControl($this->order_goods_list,'Sliding','common/pager',array('page_url'=>$this->url('analytics/default/page',array('controller'=>'Analytics', 'action'=>'classSaleStats')))) : ''; ?>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>

            </tbody>
        </table>
    </div>
</div>
<script src="<?php echo $this->basePath('/public/js/DatePicker/WdatePicker.js'); ?>"></script>
<script>
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('user_chart'), dbshop_echarts_stype);
    option = {
        title: {
            text: '<?php echo $this->translate('订单分析图表'); ?>'
        },
        tooltip : {
            trigger: 'axis'
        },
        legend: {
            data:['<?php echo $this->translate('订单数'); ?>','<?php echo $this->translate('付款订单数'); ?>']
        },
        grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
        },
        xAxis : [
            {
                type : 'category',
                boundaryGap : false,
                data : [<?php echo $this->date_str; ?>]
            }
        ],
        yAxis : [
            {
                type : 'value'
            }
        ],
        series : [
            {
                name:'<?php echo $this->translate('订单数'); ?>',
                type:'line',
                data:[<?php echo $this->week_order; ?>]
            },
            {
                name:'<?php echo $this->translate('付款订单数'); ?>',
                type:'line',
                data:[<?php echo $this->week_pay_order; ?>]
            }
        ]
    };
    myChart.setOption(option);


    function submit_form() {
        $('#order_stats_form').submit();
    }
</script>
<script>
    var goodsClassChart = echarts.init(document.getElementById('goods_class_chart'), dbshop_echarts_stype);
    option = {
        title : {
            text: '<?php echo $this->translate('商品分类商品销售'); ?>',
            x:'center'
        },
        tooltip : {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
            orient: 'vertical',
            left: 'left',
            data: [<?php echo $this->goods_class_name_str; ?>]
        },
        series : [
            {
                name: '<?php echo $this->translate('商品销售'); ?>',
                type: 'pie',
                radius : '55%',
                center: ['50%', '60%'],
                data:[
                    <?php
                    $goods_class_count = count($this->class_goods_array);
                    $p_i = 1;
                    foreach($this->class_goods_array as $p_value) {
                        if(is_array($p_value)) echo "{value:".$p_value['num'].", name:".$p_value['name']."}";
                        else echo "{value:0, name:".$p_value."}";
                        if($p_i < $goods_class_count) echo ',';

                        $p_i++;
                    } ?>
                ],
                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };
    goodsClassChart.setOption(option);

    var userGroupChart = echarts.init(document.getElementById('user_group_chart'), dbshop_echarts_stype);
    option = {
        title : {
            text: '<?php echo $this->translate('客户组购买商品'); ?>',
            x:'center'
        },
        tooltip : {
            trigger: 'item',
            formatter: "{a} <br/>{b} : {c} ({d}%)"
        },
        legend: {
            orient: 'vertical',
            left: 'left',
            data: [<?php echo $this->user_group_name_str; ?>]
        },
        series : [
            {
                name: '<?php echo $this->translate('购买商品'); ?>',
                type: 'pie',
                radius : '55%',
                center: ['50%', '60%'],
                data:[
                    <?php
                    $user_group_goods_count = count($this->user_group_goods_array);
                    $p_i = 1;
                    foreach($this->user_group_goods_array as $e_value) {
                        if(is_array($e_value)) echo "{value:".$e_value['num'].", name:".$e_value['name']."}";
                        else echo "{value:0, name:".$e_value."}";
                        if($p_i < $user_group_goods_count) echo ',';

                        $p_i++;
                    } ?>
                ],
                itemStyle: {
                    emphasis: {
                        shadowBlur: 10,
                        shadowOffsetX: 0,
                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                    }
                }
            }
        ]
    };
    userGroupChart.setOption(option);
</script>